<?php

/* Page controller class */
class smileys_handler extends _site_handler {
	public $SmileysPerPage = 25;
	public $PageNumber = 1;
	public $Smileys;
	public $HideExtras;
	public $ArchiveType;

	// Render page
	public function __construct($m, $view) {
		$this->InitializeSite($m);

		$this->HideExtras = @$_COOKIE['hide_extras'];

		$this->Wordlets->AddWordlets('smileys');

		// Get current smiley page
		@list($tmp, $page_name, $archive_type, $archive_dname, $page_number, $params) = split('/', @$_SERVER['PATH_INFO']);
		$dirs = split('/', @$_SERVER['PATH_INFO']);

		// Old url schemes:
		if ( strtolower($archive_type) == 'genres' ) {
			
		} elseif ( strtolower($archive_type) == 'categories' ) {
			
		} elseif ( $dirs[3] == 'users' || $dirs[3] == 'user' && @$dirs[4] ) {
			if ( ($page_number = intval(@$dirs[5])) ) $this->PageNumber = $page_number;
			$page_template = Monkake::Get('site_url') . 'smileys/user/' . $dirs[4] . '/{number}';
			$user = new User();
			$user->SetValuesByUrlname($dirs[4]);

			$this->Title = 'Smileys by ' . htmlspecialchars($user->Dname());
			$smileys = $user->Smileys((($this->PageNumber - 1) * $this->SmileysPerPage), $this->SmileysPerPage);
			$this->ArchiveType = 'user';
		} else {
			if ( ($page_number = intval($page_number)) ) $this->PageNumber = $page_number;
			$page_template = Monkake::Get('site_url') . 'smileys/' . $archive_dname . '/{number}';
			$this->Title = 'Smileys tagged with "' . $archive_dname . '"';

			$tag = new Tag(array('dname' => $archive_dname));

			$smileys = $tag->Smileys((($this->PageNumber - 1) * $this->SmileysPerPage), $this->SmileysPerPage);
			$this->ArchiveType = 'tag';
		}

		$this->Smileys = $smileys;

		if ( $this->Smileys->TotalCount ) {
			$pagination = $this->M->GetObject('Pagination',
				$this->Smileys->TotalCount, // item count
				$this->PageNumber, // current page
				$this->SmileysPerPage, // items per page
				$page_template, // link
				5, // jump
				3, // previous pages
				3, // next pages 
				2, // first pages
				2, // last pages
				TRUE // span
				);
	
			$this->Pagination = $pagination->Paginate();
		}

		$this->RenderViewContent($view);
	}
}

?>